class MyPromise{
    constructor(fun){

        //三种状态  pending  fulfilled  rejected
        this.status = 'pending';
        this.value = '';  //成功的数据
        this.error = ''   //错误的信息


        //成功状态触发的函数
        let resolve = (data) => {
            this.status = 'fulfilled';

            this.value = data;
        }

        //失败状态触发的函数
        let reject = (error) => {
            this.status = 'rejected';
            this.error = error;
        }

        fun(resolve,reject)
    }

    then(successFun,rejectFun){
        if(this.status === 'fulfilled'){
            successFun(this.value);
        }else if(this.status === 'rejected'){
            rejectFun(this.error);
        }
    }
}

new MyPromise((resolve,reject) => {
    // resolve('success')
    reject('error====')
}).then(res => {
    //成功的状态
    console.log(res);
},error => {
    //失败的状态
    console.log("error",error)
})